package sqlgen

import (
	"fmt"
	"strconv"
	"strings"
)

// ColonTimeToInt converts a colon time such as 11:20:03 to an integer value
// such as 40803
func ColonTimeToInt(colonDate string) (any, error) {
	split := strings.Split(colonDate, ":")

	if len(split) != 3 {
		return nil, fmt.Errorf("Error parsing ColonTimeToInt, input string: '%s'", colonDate)
	} else if h, err := strconv.Atoi(split[0]); err != nil {
		return nil, err
	} else if m, err := strconv.Atoi(split[1]); err != nil {
		return nil, err
	} else if s, err := strconv.Atoi(split[2]); err != nil {
		return nil, err
	} else {
		return h*3600 + m*60 + s, nil
	}
}
